package com.spvs.system.controller;

import com.spvs.common.core.utils.poi.ExcelUtil;
import com.spvs.common.core.web.controller.BaseController;
import com.spvs.common.core.web.domain.AjaxResult;
import com.spvs.common.core.web.page.TableDataInfo;
import com.spvs.common.log.annotation.Log;
import com.spvs.common.log.enums.BusinessType;
import com.spvs.system.domain.SysUserAutograph;
import com.spvs.system.service.ISysUserAutographService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户签名Controller
 *
 * @author supervision
 * @date 2024-06-23
 */
@RestController
@RequestMapping("/autograph")
public class SysUserAutographController extends BaseController
{
    @Autowired
    private ISysUserAutographService sysUserAutographService;

    /**
     * 查询用户签名列表
     */
    // // @RequiresPermissions("system:autograph:list")
    @GetMapping("/list")
    public TableDataInfo list(SysUserAutograph sysUserAutograph)
    {
        startPage();
        List<SysUserAutograph> list = sysUserAutographService.selectSysUserAutographList(sysUserAutograph);
        return getDataTable(list);
    }

    /**
     * 导出用户签名列表
     */
    // @RequiresPermissions("system:autograph:export")
    @Log(title = "用户签名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserAutograph sysUserAutograph)
    {
        List<SysUserAutograph> list = sysUserAutographService.selectSysUserAutographList(sysUserAutograph);
        ExcelUtil<SysUserAutograph> util = new ExcelUtil<SysUserAutograph>(SysUserAutograph.class);
        util.exportExcel(response, list, "用户签名数据");
    }

    /**
     * 获取用户签名详细信息
     */
    // @RequiresPermissions("system:autograph:query")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(sysUserAutographService.selectSysUserAutographByUserId(userId));
    }


    /**
     * 新增用户签名
     */
    // @RequiresPermissions("system:autograph:add")
    @Log(title = "用户签名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserAutograph sysUserAutograph)
    {
        return toAjax(sysUserAutographService.insertSysUserAutograph(sysUserAutograph));
    }

    /**
     * 修改用户签名
     */
    // @RequiresPermissions("system:autograph:edit")
    @Log(title = "用户签名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserAutograph sysUserAutograph)
    {
        return toAjax(sysUserAutographService.updateSysUserAutograph(sysUserAutograph));
    }

    /**
     * 删除用户签名
     */
    // @RequiresPermissions("system:autograph:remove")
    @Log(title = "用户签名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(sysUserAutographService.deleteSysUserAutographByUserIds(userIds));
    }
}
